package com.shxy.dao.base;

import com.shxy.entity.custom.CustomClazz;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 班级信息访问接口
 */
@Repository
public interface ClazzDao extends JpaRepository<CustomClazz, Integer> {

    /**
     * 获取所有班级
     * @return
     */
    @Cacheable(cacheNames = "clazz_all")
    List<CustomClazz> findAll();

    /**
     * 判断班级名称是否存在
     * @param name
     * @return
     */
    Boolean existsByName(String name);

    /**
     * 根据名称和学院查询班级
     * @param name
     * @param year
     * @return
     */
    @Cacheable(cacheNames = "clazz_by_name_year")
    Optional<CustomClazz> findFirstByNameAndYear(String name, String year);

    /**
     * 查询指定年份的班级
     * @param year
     * @return
     */
    @Cacheable(cacheNames = "clazz_by_year")
    List<CustomClazz> findByYear(String year);
}
